package models.statistics;

import exceptions.InvalidParameterException;
import models.CompressionAlgorithmType;
import models.FileInfo;

import javax.persistence.*;

@Entity
@Table(name = "SLPCartesianStatistics")
public class SLPCartesianStatistics extends CompressionStatsBase implements ISLPCompressionStats {

    @Id
    @Column(name = "id", length = 50)
    public String id;


    @Column(name = "slpBuildingTime")
    public long slpBuildingTime;

    @Column(name = "length")
    public long length;

    @Column(name = "countRules")
    public long countRules;

    @Column(name = "height")
    public long height;

    @OneToOne(cascade = CascadeType.ALL)
    public FileInfo fileInfo;

    public SLPCartesianStatistics() {
    }

    public SLPCartesianStatistics(String id, long slpBuildingTime, long length, long countRules, long height, FileInfo fileInfo) {
        this.id = id;
        this.slpBuildingTime = slpBuildingTime;
        this.length = length;
        this.countRules = countRules;
        this.height = height;
        this.fileInfo = fileInfo;
    }
    @Override
    public long calcTextSize(int reductionRate) throws InvalidParameterException {
        return calcReducedValue(fileInfo.fileSize, reductionRate);
    }

    @Override
    public float calcCompressionRate() {
        return calcCompressionRate(fileInfo.fileSize, countRules);
    }

    @Override
    public long calcCompressionTime(int reductionRate) throws InvalidParameterException {
        return calcReducedValue(slpBuildingTime, reductionRate);
    }

    @Override
    public int slpHeight() {
        return (int) height;
    }

    @Override
    public CompressionAlgorithmType algorithmType() {
        return CompressionAlgorithmType.slpCartesian;
    }
}
